import os

from django.conf import settings
from django.views import View

from User.models import User, Order
from Venue import Constants
from sportsground.utils import Req
from sportsground.utils.Res import Res
from sportsground.utils.views import LoginRequiredVenue


class UsersView(LoginRequiredVenue,View):
    """ 管理用户 """

    def get(self, request):
        """ 查询 """
        users = User.objects.all()
        lists = []
        for user in users:
            lists.append(user.Info())
            orders = []
            ords = Order.objects.filter(user=user).order_by('-createTime').all()
            for ord in ords:
                orders.append(ord.oid)
            lists[-1]['orders'] = orders
        return Res.Json(Res.OK, result=lists)
